package com.xinxin.base.converter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.xinxin.base.util.DateTimeUtil;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * @author ys
 * @date 2020/7/16
 */
public class LocalDataTime2TimestampSerializer extends JsonSerializer<LocalDateTime> {

    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeNumber(value.toInstant(DateTimeUtil.CST_OFFSET).toEpochMilli());
    }
}
